/***************************************************************************
 *   Copyright (C) 2007 by Vishwajeet   *
 *   vishwajeet@qcomputingproject.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#include "MainWindowVish.h"

#include "CustomProxyWidget.h"

MainWindowVish::MainWindowVish ( QWidget *parent )
    : QMainWindow ( parent )
{
  setupUi ( this );
  m_pClassic = new ClassicWindowVish(m_pClassicViewVish);

  m_pClassicViewVish->setVisible(false);
  isClassicView = false;
  listOfImages.clear();
  setupImageScene();
  connect(m_pSwitchViewerButton,SIGNAL(clicked()),this,SLOT(switchView()));
}

MainWindowVish::~MainWindowVish()
{
  delete m_pClassic;
}

void MainWindowVish::switchView()
{
  if (isClassicView)
    {
      m_pClassicViewVish->setVisible(false);
      AnimatedViewVish->setVisible(true);
      isClassicView = false;

    }
  else
    {
      AnimatedViewVish->setVisible(false);
      m_pClassicViewVish->setVisible(true);
      isClassicView = true;

    }
}

void MainWindowVish::setupImageScene()
{
qDebug("Setup Image scene");
  QGraphicsScene *scene = new QGraphicsScene;

  for (int y = 0; y < 4; ++y)
    {
      for (int x = 0; x < 10; ++x)
        {
          CustomProxyWidget *proxy = new CustomProxyWidget(0, Qt::Window);
	  ImageFrame *imageFrame = new 	ImageFrame();
	  listOfImages.append(imageFrame);	
          //CustomLabel *proxy = new CustomLabel();
          //proxy->setWidget(new EmbeddedDialog);
          //proxy->setWidget(new CustomLabel());
	  proxy->setWidget(imageFrame);
          QRectF rect = proxy->boundingRect();
          proxy->setPos(x * rect.width() * 1.05, y * rect.height() * 1.05);
          //proxy->setPos(x * rect.width() , y * rect.height() );
          proxy->setCacheMode(QGraphicsItem::NoCache);

          scene->addItem(proxy);
        }
    }
  scene->setSceneRect(scene->itemsBoundingRect());

  AnimatedViewVish->setScene(scene);
  //QGraphicsView view(&scene);
  //view.scale(0.5, 0.5);
  AnimatedViewVish->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing | QPainter::TextAntialiasing);
  AnimatedViewVish->setBackgroundBrush(QPixmap("/home/gokul/ByVishwajeet/QVish/src/No-Ones-Laughing-3.jpg"));
  AnimatedViewVish->setCacheMode(QGraphicsView::CacheNone);
  AnimatedViewVish->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
  AnimatedViewVish->show();
  AnimatedViewVish->setWindowTitle("VishViewer");

}

void MainWindowVish::setImageForAnimatedView(int position)
{
    //listOfImages.at(position)->setImage();	
}

